home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / msdemo.zip / MOUSE.ASM < prev    next >
Assembly Source File  |  1993-01-04  |  9KB  |  257 lines

  1. %title "Mouse routines"
  2.  
  3.         IDEAL
  4.  
  5. CrtWidth        equ     (Byte Ptr 4AH)
  6.  
  7. segment         data    word    public
  8.         extrn  MousePresent:word
  9.         extrn  EventFlag:word
  10.         extrn  Xcoord:byte
  11.         extrn  Ycoord:byte
  12.         extrn  Buttons:word
  13.         extrn  MCursorAddr:word
  14.         extrn  MouseOn:word
  15. ends
  16.  
  17.  
  18. segment         code    word    public
  19.         assume  cs:code,ds:data
  20.  
  21. PUBLIC  MouseRegister
  22. ;====================================================================
  23. ; The procedure 'MouseRegister' is called to test for the presense
  24. ; of a mouse as well as register the mouse handler with MOUSE.SYS
  25. ;
  26. ; On entry:
  27. ;       BP + 6 = Event mask to use in registeration.
  28. ;       DS = Turbo Pascal data segment
  29. ;
  30. ; On exit:
  31. ;       AX, BX, CX, DX affected
  32. ;       Mouse status variables set accordingly.
  33. ;         If mouse driver not present:
  34. ;               MousePresent = 0
  35. ;               EventFlag    = 0
  36. ;               Xcoord       = -1
  37. ;               Ycoord       = -1
  38. ;               Buttons      = 0
  39. ;               MCursorAddr  = -1
  40. ;               MouseOn      = 0
  41. ;         If mouse driver is present:
  42. ;               MousePresent = 1
  43. ;               EventFlag    = 0   Until 1st mouse event occurs
  44. ;               Xcoord       = -1  Until 1st mouse event occurs
  45. ;               Ycoord       = -1  Until 1st mouse event occurs
  46. ;               Buttons      = 0   Until 1st mouse event occurs
  47. ;               MCursorAddr  = -1  Until 1st mouse event occurs
  48. ;               MouseOn      = 0
  49. ;
  50. ;
  51. proc    MouseRegister   far
  52.         push    bp
  53.         mov     bp,sp
  54.         push    es                      ;Save ES register
  55.  
  56. ;Initialize external mouse status variables
  57.  
  58.         mov     [MousePresent],0        ;Start with mouse not present
  59.         mov     [EventFlag],0           ;Initialize event flag
  60.         mov     [Xcoord],-1             ;Initial X off screen
  61.         mov     [Ycoord],-1             ;Initial Y off screen
  62.         mov     [MouseOn],0             ;Show mouse is off
  63.         mov     [Buttons],0             ;Initial button status idle
  64.         mov     [MCursorAddr],-1        ;Initial Addr off screen
  65.  
  66. ;Check to see if mouse driver present
  67.  
  68.         mov     ah,35h                  ;Get Int vector
  69.         mov     al,33h                  ;For mouse
  70.         int     21h                     ;Call DOS
  71.         mov     ax,es                   ;Move segment to AX
  72.         or      ax,bx                   ;Is vector 0
  73.         jz      @@Exit                  ;Yes, so exit
  74.         mov     al,[es:bx]              ;Get first byte pointed to
  75.         cmp     al,0CFh                 ;Does it point to an IRET
  76.         je      @@Exit                  ;Yes, so no mouse
  77.  
  78. ;Driver is present
  79.  
  80.         mov     ax,0                    ;Reset mouse
  81.         int     33h                     ;Call mouse driver
  82.         mov     [MousePresent],1        ;Show mouse status
  83.         push    cs
  84.         pop     es                      ;ES:DX = handler address
  85.         mov     dx,offset CS:MouseHandler
  86.         mov     cx,[BP+6]               ;CX = event mask
  87.         mov     ax,0Ch                  ;Register handler
  88.         int     33h                     ;Call mouse driver
  89.  
  90. ;Set mouse cursor in software
  91.  
  92.         mov     ax,10                   ;Set text cursor
  93.         mov     bx,0                    ;Cursor in software
  94.         mov     cx,009FFh               ;Makes text cursor red background
  95.         mov     dx,4000h
  96.         int     33h
  97. @@Exit:
  98.         pop     es                      ;Restore ES register
  99.         pop     bp
  100.         ret     2
  101. endp    MouseRegister
  102.  
  103.  
  104.  
  105. PUBLIC  MouseUnregister
  106. ;======================================================================
  107. ; Unregister mouse if present
  108. ;
  109. ; On entry:
  110. ;       DS = Turbo Pascal data segment
  111. ;
  112. ; On exit:
  113. ;       AX affected
  114. ;
  115. proc    MouseUnregister far
  116.         test    [MousePresent],1        ;Get mouse status
  117.         jz      @@Exit                  ;Mouse not present
  118.         mov     ax,0                    ;Function 0 reset mouse driver
  119.         int     33h                     ;Call mouse driver
  120.         mov     [MousePresent],0
  121. @@Exit:
  122.         ret
  123. endp    MouseUnregister
  124.  
  125.  
  126.  
  127.  
  128. ;=======================================================================
  129. ; This procedure is called only by the mouse driver software and so is
  130. ; not decalared public. The procedure 'MouseRegister' should be called
  131. ; to register this routine with the mouse driver software. When a mouse
  132. ; event occurs corresponding to the event mask passed in the call to the
  133. ; 'MouseRegister' procedure, this routine will be entered with a far call
  134. ; from the mouse driver.  At entry to the handler, the registers are set
  135. ; up as follows:
  136. ;
  137. ;       AX = mouse event flags (bits set signal a corresponding event):
  138. ;              BIT      SIGNIFICANCE
  139. ;               0       mouse movement
  140. ;               1       left button pressed
  141. ;               2       left button released
  142. ;               3       right button pressed
  143. ;               4       right button released
  144. ;               5-15    reserved
  145. ;       BX = Button state
  146. ;               bit     significance
  147. ;               0       left button is down
  148. ;               1       right button is down
  149. ;               2-15    reserved
  150. ;       CX = X coordinate (0 to 632)
  151. ;       DX = Y coordinate (0 to 192)
  152. ;       SI = raw vertical mickey count
  153. ;       DI = raw horizontal mickey count
  154. ;       DS = mouse driver data segment
  155. ;
  156. ; On exit:
  157. ;       Mouse status variables are updated to reflect the event.
  158. ;
  159. proc    MouseHandler    far
  160.         push    ds                      ;Save mouse data segment
  161.  
  162.         mov     di,data                 ;Make our data segment addressable
  163.         mov     ds,di
  164.         assume  ds:data
  165.  
  166.         shr     cx,1                    ;Put X coord in the range (0-79)
  167.         shr     cx,1                    ; by dividing by 8
  168.         shr     cx,1
  169.         mov     [Xcoord],cl             ;Store X coord
  170.         shr     dx,1                    ;Put Y coord in the range (0-24)
  171.         shr     dx,1                    ; by dividing by 8
  172.         shr     dx,1
  173.         mov     [Ycoord],dl             ;Store Y coord
  174.         mov     [Buttons],bx            ;Store button data
  175.         mov     [EventFlag],ax          ;Save type of event
  176.  
  177. ;Compute screen offset address of mouse position
  178.  
  179.         mov     ax,40h
  180.         mov     es,ax                   ;ES = Segment of BIOD data area
  181.         mov     al,dl                   ;AX = Y coordinate
  182.         mul     [es:CrtWidth]           ; times the screen width
  183.         add     ax,cx                   ; add in X position offset
  184.         shl     ax,1                    ; adjust for character attribute
  185.         mov     [MCursorAddr],ax        ;Save it
  186.  
  187.         pop     ds                      ;Restore mouse data segment
  188.         ret
  189. endp    MouseHandler
  190.  
  191.  
  192.  
  193.  
  194. PUBLIC  HideMouse
  195. ;==================================================================
  196. ; Hide the mouse cursor
  197. ;
  198. ; On entry:
  199. ;       Nothing.
  200. ;
  201. ; On exit:
  202. ;       All registers preserved.
  203. ;
  204. proc    HideMouse       far
  205.         push    ax                      ;Save registers
  206.         push    ds
  207.  
  208.         mov     ax,data
  209.         mov     ds,ax                   ;DS = data segment
  210.         test    [MousePresent],1        ;Mouse present?
  211.         jz      @@Exit                  ;No
  212.         test    [MouseOn],1             ;Is mouse cursor displayed?
  213.         jz      @@Exit                  ;No
  214.         mov     ax,2                    ;Hide mouse function
  215.         int     33h
  216.         mov     [MouseOn],0             ;Set mouse on status OFF
  217. @@Exit:
  218.         pop     ds                      ;Restore registers
  219.         pop     ax
  220.         ret
  221. endp    HideMouse
  222.  
  223.  
  224.  
  225.  
  226. PUBLIC  ShowMouse
  227. ;==================================================================
  228. ; Show the mouse cursor
  229. ;
  230. ; On entry:
  231. ;       Nothing.
  232. ;
  233. ; On exit:
  234. ;       All registers preserved.
  235. ;
  236. proc    ShowMouse       far
  237.         push    ax                      ;Save registers
  238.         push    ds
  239.  
  240.         mov     ax,data
  241.         mov     ds,ax                   ;DS = data segment
  242.         test    [MousePresent],1        ;Mouse present?
  243.         jz      @@Exit                  ;No
  244.         test    [MouseOn],1             ;Is mouse cursor displayed
  245.         jnz     @@Exit                  ;Yes
  246.         mov     ax,1                    ;Show mouse function
  247.         int     33h
  248.         mov     [MouseOn],1             ;Set mouse on status ON
  249. @@Exit:
  250.         pop     ds                      ;Restore registers
  251.         pop     ax
  252.         ret
  253. endp    ShowMouse
  254. ends
  255. end
  256.  
  257.